/* 
 * e.c - Many ways to calculate the irrational number e (Euler's number)
 */

#include <math.h>

/*
 *     ∞
 * e = ∑ (1⁄n!) = 1⁄0! + 1⁄1! + 1⁄2! + 1⁄3! + …
 *    n=0
 */
double
e_series(long n)
{
	long i;
	long fact = 1;
	double e = 1.0;
	for (i=1; i < n; i++) {
		fact *= i;
		e += (1.0 / (double)fact);
	}
	return e;
}

/*
 *                  x
 * e ≡ lim (1 + 1⁄x)
 *     x→∞
 */
double
e_limit(double x)
{
	double e;
	e = 1.0 + (1.0 / x);
	return pow(e, x);
}
